﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace GameName1
{
    public static class LoginClient
    {
        public static void Login(string username, string password)
        {
            string url = "http://151.80.150.28/register.php";
            Uri uri = new Uri(url, UriKind.Absolute);
            StringBuilder postData = new StringBuilder();
            postData.AppendFormat("{0}={1}", "name", HttpUtility.UrlEncode(username));
            postData.AppendFormat("&{0}={1}", "email", HttpUtility.UrlEncode(password));
            WebClient client = new WebClient();

            // Add a user agent header in case the  
            // requested URI contains a query.

            client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();

            client.UploadStringCompleted += client_UploadStringCompleted;
            client.UploadProgressChanged += client_UploadProgressChanged;

            client.UploadStringAsync(uri, "POST", postData.ToString());

        }



        private static void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
        {
            
        }

        private static void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            if (e.Cancelled == false & e.Error == null)
            {
                //prog.IsVisible = false;
                string[] result = e.Result.ToString().Split('|');
                Debug.WriteLine(result);
               // string strStatus = result[0].ToString();
               // string strMemberID = result[1].ToString();
               // string strError = result[2].ToString();
            }
        }

    }
}
